<?php
require_once 'PDO.class.php';

class Quiz extends PDOClass{

	public function __construct()
	{
		parent::__construct();
	}
	
	public function o_fGetListQuiz()
	{
		$o_Quiz = new stdClass();
		$sql="SELECT q.*,c.cat_name as name FROM wof_quiz as q
				  INNER JOIN wof_cat as c
				  ON q.quiz_cat_id = c.cat_id
				  ORDER BY q.quiz_id ASC";
		$statement = $this->db->query($sql);
		$statement->execute();
		$statement->setFetchMode(PDO::FETCH_OBJ);
		$i= 0;	
		while ($row = $statement->fetch())
		{
			$a_Quiz = array();
			$a_Quiz['id'] = $row->quiz_id;
			$a_Quiz['question'] = $row->quiz_question;
			$a_Quiz['answer'] = $row->quiz_answer;
			$a_Quiz['name'] = $row->name;
			$o_Quiz->{$i} =$a_Quiz;

			$i++;
		}
		return $o_Quiz;
	}
	
	public function o_fGetQuizById($id)
	{
		$o_Quiz = new stdClass();
		$sql="SELECT * FROM wof_quiz WHERE quiz_id=".$id."";
		$statement = $this->db->query($sql);
		$statement->execute();
		$statement->setFetchMode(PDO::FETCH_OBJ);
		return $statement->fetch();
	}
	
	public function b_fUpdateQuiz($a_Quiz)
	{
		$sql = "
				UPDATE wof_quiz
				SET quiz_question = ?, quiz_answer = ?, quiz_cat_id =? WHERE quiz_id = ?";
		$statement = $this->db->prepare($sql);
		return $statement->execute($a_Quiz);
	}
	
	public function b_fInsertQuiz($a_Data)
	{
		$sql = "
		INSERT INTO wof_quiz (quiz_question, quiz_answer, quiz_cat_id)
		VALUES (?,?,?)";
		$statement = $this->db->prepare($sql);
		return $statement->execute($a_Data);
	}
	
	
	public function o_fDeleteQuizById($id)
	{
		$sql="DELETE FROM wof_quiz WHERE quiz_id=".$id."";
		$statement = $this->db->prepare($sql);
		return $statement->execute();
	}
	
}
$o_QuizModel = new Quiz();
?>
